﻿using System.Web.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SacNetUG.Controllers;
using SacNetUG.Models;
using SacNetUG.Tests.Fakes;
using System.Web.Mvc;
using MvcContrib.TestHelper;
using Rhino.Mocks;

namespace SacNetUG.Tests.Controllers
{
    [TestClass]
    public class EventControllerTest
    {
        private ISacNetUGRepository repository;
        private MyFakeDatabase db;
        private FakeDataContextWrapper dataContext;
        private EventController controller;

        [TestInitialize]
        public void SetUp()
        {
            db = new MyFakeDatabase();
            dataContext = new FakeDataContextWrapper(db);
            repository = new SacNetUGRepository(dataContext);
            controller = new EventController(repository);

            controller.SetFakeControllerContext();

            RouteTable.Routes.Clear();
            RouteTable.Routes.MapRoute(
                "SpecialEvent",
                "SpecialEvent",
                new { controller = "Event", action = "Detail", id = "1" }
                );
        }

        [TestCleanup]
        public void TearDown()
        {
            RouteTable.Routes.Clear();
        }

        [TestMethod]
        public void DetailReturnsNotFoundGivenInvalidEventId()
        {
            // Arrange
            var invalidEventId = -1;

            // Act
            var result = controller.Detail(invalidEventId) as ViewResult;

            // Assert
            Assert.AreEqual("NotFound", result.ViewName);
        }

        [TestMethod]
        public void SpecialEventRouteTest()
        {
            "~/SpecialEvent".Route().ShouldMapTo<EventController>(x => x.Detail(1));
        }
    }
}